package logic

import (
	"context"
	"cp/cprpc/cprpcclient"

	"cp/api/internal/svc"
	"cp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CourseAddLogic) CourseAdd(req *types.CourseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CpRpc.CourseAdd(l.ctx, &cprpcclient.CourseAddRequest{
		Title:         req.Title,
		TeacherId:     int64(req.TeacherId),
		Category:      req.Category,
		Price:         float32(req.Price),
		OriginalPrice: float32(req.OriginalPrice),
		CourseImage:   req.CourseImage,
		Intro:         req.Intro,
		LearnCount:    int64(req.LearnCount),
		Status:        req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "课程发布成功",
		Data:    add,
		Code:    200,
	}, nil

}
